package com.qf.pojo;

import java.util.List;

//第七步，7.1由登录服务端跳转到图书分页服务端，先封装分页属性
public class PageBean<T> {
    //封装分页属性
    private int pageSize;//每页显示条数
    private int PageNum;//
    private long totalSize;//总条数，从数据库中获取的
    private int pageCount;//总页数
    private List<T> data;//当前分页数据 T飘红，快捷键选择最后一行，使得PageBean后面多了一个<T>
    //后加，优化分页条
    private int startPage;//起始页
    private int endPage;//结束页

    public PageBean() {
    }
    //有参构造方法选择其中四个参数pageSize，PageNum，totalSize，List<T> data

    public PageBean(int pageSize, int pageNum, long totalSize, List<T> data) {
        this.pageSize = pageSize;
        PageNum = pageNum;
        this.totalSize = totalSize;
        this.data = data;

        //总页数需要公式计算 起始页和结束页也需要公式不能自动生成
        //总页数：如果总数据totalSize能整除pageSize，结果就是总页数，有余数，商加1，并且强转为int整数类型
        this.pageCount=(int) (totalSize%pageSize==0?totalSize/pageSize:totalSize/pageSize+1);
        //正常情况下，1~5页码条不变，从5开始左右显示页码各加一，总共显示十页
        this.startPage=pageNum-4;
        this.endPage=pageNum+5;
        //非正常情况下
        if (pageNum<=5){
            this.startPage=1;
            this.endPage=10;
        }
        if (pageNum>=this.pageCount-5){
            this.startPage=this.pageCount-9;
            this.endPage=this.pageCount;
        }
        if (this.pageCount<=10){
            this.startPage=1;
            this.endPage=this.pageCount;
        }

    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return PageNum;
    }

    public void setPageNum(int pageNum) {
        PageNum = pageNum;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageSize=" + pageSize +
                ", PageNum=" + PageNum +
                ", totalSize=" + totalSize +
                ", pageCount=" + pageCount +
                ", data=" + data +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                '}';
    }
}
